import { ref } from "vue";
import { get } from "lodash-es";
import { getCheckResultByPurchaseItem } from "@/api/tradein/tradein.api";

export const useCheckResultModal = () => {
  const showCheckResult = ref<boolean>(false);
  const checkResultList = ref<any[]>([]);
  const checkResultTitle = ref<string>("");

  const handltToggleShowCheckResult = (payload: boolean) => {
    showCheckResult.value = payload;
  };

  const handleGetCheckResult = async (itemId: string, variantName: string) => {
    try {
      const result = await getCheckResultByPurchaseItem(itemId);
      checkResultTitle.value = `${variantName}的问题清单`;
      checkResultList.value = get(result, "result") || [];
      showCheckResult.value = true;
    } catch (error) {
      console.log(error);
    }
  };

  return {
    showCheckResult,
    checkResultList,
    checkResultTitle,
    handltToggleShowCheckResult,
    handleGetCheckResult,
  };
};
